﻿using System;
using System.Linq.Expressions;

using App.Model.ReturnModel;
using App.IRepository;
using SqlSugar;

namespace App.Bussiness
{
    public abstract class BaseBLL<T> where T : class, new()
    {
        protected IBase<T> CurrentRepository
        {
            get;
            set;
        }
        public BaseBLL()
        {
            SetCurrentRepository();
        }
        public abstract void SetCurrentRepository();

        public T GetById(long id)
        {
            return CurrentRepository.Get(id);
        }

        public TableModel<T> GetPageList(int pageIndex, int pageSize)
        {
            Expression<Func<T, bool>> where = (p => true);
            return CurrentRepository.GetPageList(where, pageIndex, pageSize);
        }

        public TableModel<T> GetPageList(Expression<Func<T, bool>> where, int pageIndex, int pageSize, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
        {
            return CurrentRepository.GetPageList(where, pageIndex, pageSize, orderByExpression, orderByType);
        }

        public bool Add(T entity)
        {
            return CurrentRepository.Add(entity);
        }

        public bool Update(T entity)
        {
            return CurrentRepository.Update(entity);
        }

        public bool Dels(dynamic[] ids)
        {
            return CurrentRepository.Dels(ids);
        }

        public T GetByWhere(Expression<Func<T, bool>> where)
        {
            return CurrentRepository.GetByWhere(where);
        }

    }
}
